package com.baibei.pay.withdraw;

import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.baibei.pay.R;
import com.baibei.pay.R2;
import com.blankj.utilcode.utils.ScreenUtils;
import com.rae.widget.dialog.impl.SlideDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 成功提现碎片
 * Created by shenminjie on 2017/8/16.
 * mail:shenminjie@100bei.com
 */

public class WithdrawSuccessFragment extends DialogFragment {

    Unbinder unbinder;
    @BindView(R2.id.container)
    LinearLayout mContainer;

    /**
     * 监听事件
     */
    private OnSuccessListener mListener;

    /**
     * 设置回调
     *
     * @param listener listener
     */
    public void setOnListener(OnSuccessListener listener) {
        this.mListener = listener;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_withdraw_success, container, false);
        unbinder = ButterKnife.bind(this, view);
        //全屏
        ViewGroup.LayoutParams layoutParams = mContainer.getLayoutParams();
        layoutParams.width = ScreenUtils.getScreenWidth();
        layoutParams.height = ScreenUtils.getScreenHeight();
        mContainer.setLayoutParams(layoutParams);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        //透明
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.0f;
        window.setAttributes(windowParams);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new SlideDialog(getContext());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }

    @OnClick(R2.id.tv_certain)
    public void onViewClicked() {
        if (mListener != null) {
            mListener.onSuccessListener(this);
        }
    }

    @Override
    public void onCancel(DialogInterface dialog) {
        super.onCancel(dialog);
        onViewClicked();
    }

    /**
     * 回调
     */
    public interface OnSuccessListener {
        /**
         * 回调
         *
         * @param fragment fragment
         */
        void onSuccessListener(DialogFragment fragment);
    }

}
